package kandl.automation.spring.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.client.RestTemplate;

import java.net.MalformedURLException;
import java.net.URL;

import kandl.automation.reporting.ResultReporter;
import kandl.automation.reporting.testrail.TestRailReporter;
import kandl.automation.reporting.testrail.TestRailRepository;
import kandl.automation.steprunner.selenium.RemoteWebDriverFactory;
import kandl.automation.steprunner.selenium.WebDriverFactory;

@Configuration
@Profile("ci")
public class HudsonConfig {

    @Autowired
    private TestRailRepository testRailRepository;


    @Bean
    public ResultReporter resultReporter() {
        return new TestRailReporter(testRailRepository);
    }

    @Bean
    @Autowired
    public TestRailRepository testRailRepository(@Value("${testrail.api.url}") String baseUrl, RestTemplate restTemplate) {
        return new TestRailRepository(baseUrl, restTemplate);
    }

    @Bean
    public WebDriverFactory webDriverFactory(@Value("${selenium.saucelabs.url}") String url) throws MalformedURLException {
        return new RemoteWebDriverFactory(new URL(url));
    }
}
